package cn.jeeweb.modules.web.labor.service.impl;

import cn.jeeweb.core.common.service.impl.CommonServiceImpl;
import cn.jeeweb.core.query.data.PageImpl;
import cn.jeeweb.core.query.data.Pageable;
import cn.jeeweb.core.query.data.Queryable;
import cn.jeeweb.core.query.parse.QueryToWrapper;
import cn.jeeweb.modules.web.civil.entity.HuCivilMsg;
import cn.jeeweb.modules.web.civil.mapper.HuCivilMsgMapper;
import cn.jeeweb.modules.web.expertise.entity.HuExpertiseMsg;
import cn.jeeweb.modules.web.expertise.mapper.HuExpertiseMsgMapper;
import cn.jeeweb.modules.web.human.entity.HuHumanMsg;
import cn.jeeweb.modules.web.human.mapper.HuHumanMsgMapper;
import cn.jeeweb.modules.web.labor.content.HuLaborContent;
import cn.jeeweb.modules.web.labor.entity.*;
import cn.jeeweb.modules.web.labor.mapper.*;
import cn.jeeweb.modules.web.labor.service.IHuLaborService;
import com.baomidou.mybatisplus.mapper.Wrapper;
import cn.jeeweb.core.query.data.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.sql.Timestamp;
import java.util.List;

/**
 * @Title: hu_labor
 * @Description: hu_labor
 * @author &Iacute;&otilde;&acute;&aelig;&frac14;&ucirc;
 * @date 2018-01-31 15:03:08
 * @version V1.0   
 *
 */
@Transactional
@Service("huLaborService")
public class HuLaborServiceImpl  extends CommonServiceImpl<HuLaborMapper,HuLabor> implements  IHuLaborService {

    @Resource
    private HuLaborMapper huLaborMapper;

    @Resource
    private HuEmployMentMapper huEmployMentMappper;

    @Resource
    private HuEmployTrainMapper huEmployTrainMapper;

    @Resource
    private HuEmployAutoMapper huEmployAutoMapper;

    @Resource
    private HuEmployPublicMapper huEmployPublicMapper;

    @Resource
    private HuCivilMsgMapper huCivilMsgMapper;

    @Resource
    private HuExpertiseMsgMapper huExpertiseMsgMapper;

    @Resource
    private HuHumanMsgMapper huHumanMsgMapper;


    public List<HuLabor> selectPoorList(){
        return huLaborMapper.selectPoorList();
    }


    public void insertLabor(HuLabor huLabor, HuEmployMent huEmployMent, HuHumanMsg humanMsg, HuCivilMsg huCivilMsg, HuExpertiseMsg expertiseMsg) {

        //基本信息
        huLabor.setHomeAddress(huLabor.getTownLabel()+huLabor.getVillage());
        huLabor.setHousehold(huLabor.getTownLabel()+huLabor.getVillage());
        huLaborMapper.insert(huLabor);
        //就业股基本信息

        huEmployMent.setCreateBy(huLabor.getCreateBy());
        huEmployMent.setCreateDate(huLabor.getCreateDate());
        huEmployMentMappper.insert(huEmployMent);
        if (huEmployMent.getEmployment() != null) {
            switch (huEmployMent.getEmployment()) {
                //转移就业信息
                case 1:
                    HuEmployTrain huEmployTrain = new HuEmployTrain();
                    huEmployTrain.setInfoId(huLabor.getId());
                    huEmployTrain.setCreateBy(huLabor.getCreateBy());
                    huEmployTrain.setCreateDate(new Timestamp(System.currentTimeMillis()));
                    huEmployTrainMapper.insert(huEmployTrain);
                    break;
                //自主创业管理
                case 2:
                    HuEmployAuto huEmployAuto = new HuEmployAuto();
                    huEmployAuto.setInfoId(huLabor.getId());
                    huEmployAuto.setCreateBy(huLabor.getCreateBy());
                    huEmployAuto.setCreateDate(new Timestamp(System.currentTimeMillis()));
                    huEmployAutoMapper.insert(huEmployAuto);
                    break;
                //特设公益性管理
                case 3:
                    HuEmployPublic huEmployPublic = new HuEmployPublic();
                    huEmployPublic.setInfoId(huLabor.getId());
                    huEmployPublic.setCreateBy(huLabor.getCreateBy());
                    huEmployPublic.setCreateDate(new Timestamp(System.currentTimeMillis()));
                    huEmployPublic.setStateInfo("3");
                    huEmployPublicMapper.insert(huEmployPublic);
                    break;
                //公益性岗位管理
                case 4:
                    HuEmployPublic huEmployPublic_4 = new HuEmployPublic();
                    huEmployPublic_4.setInfoId(huLabor.getId());
                    huEmployPublic_4.setCreateBy(huLabor.getCreateBy());
                    huEmployPublic_4.setCreateDate(new Timestamp(System.currentTimeMillis()));
                    huEmployPublic_4.setStateInfo("4");
                    huEmployPublicMapper.insert(huEmployPublic_4);
                    break;
                //公益专岗
                case 5:
                    HuEmployPublic huEmployPublic_5 = new HuEmployPublic();
                    huEmployPublic_5.setInfoId(huLabor.getId());
                    huEmployPublic_5.setCreateBy(huLabor.getCreateBy());
                    huEmployPublic_5.setCreateDate(new Timestamp(System.currentTimeMillis()));
                    huEmployPublic_5.setStateInfo("5");
                    huEmployPublicMapper.insert(huEmployPublic_5);
                    break;
            }
        }

        //人力资源股信息
        humanMsg.setLaborId(huLabor.getId());
        humanMsg.setCreateBy(huLabor.getCreateBy());
        humanMsg.setCreateDate(new Timestamp(System.currentTimeMillis()));
        huHumanMsgMapper.insert(humanMsg);
        //公务员股信息
        huCivilMsg.setLaborId(huLabor.getId());
        huCivilMsg.setCreateBy(huLabor.getCreateBy());
        huCivilMsg.setCreateDate(new Timestamp(System.currentTimeMillis()));
        huCivilMsgMapper.insert(huCivilMsg);
        //专技股信息
        expertiseMsg.setId(expertiseMsg.getLaborId());
        expertiseMsg.setCreateBy(huLabor.getCreateBy());
        expertiseMsg.setCreateDate(new Timestamp(System.currentTimeMillis()));
        huExpertiseMsgMapper.insert(expertiseMsg);
    }

    public Page<HuLaborContent> selectAllList(Queryable queryable, Wrapper<HuLaborContent> wrapper){
        QueryToWrapper<HuLaborContent> queryToWrapper = new QueryToWrapper<HuLaborContent>();
        queryToWrapper.parseCondition(wrapper, queryable);
        // 排序问题
        queryToWrapper.parseSort(wrapper, queryable);
        Pageable pageable = queryable.getPageable();
        com.baomidou.mybatisplus.plugins.Page<HuLaborContent> content = new com.baomidou.mybatisplus.plugins.Page<HuLaborContent>(
                pageable.getPageNumber(), pageable.getPageSize());
        List<HuLaborContent> list=huLaborMapper.selectAllList(content);
        content.setRecords(list);
        return new PageImpl<HuLaborContent>(content.getRecords(), queryable.getPageable(), content.getTotal());
    }


    @Override
    public Integer selectCount() {
        return baseMapper.selectCount();
    }
}
